<template>
<v-md-editor
    v-loading.fullscreen.lock="runloading"
v-model="mdtext" height="570px"
@save="onsave"/>
</template>
<script>
import '@kangc/v-md-editor/lib/style/base-editor.css';
import '@kangc/v-md-editor/lib/theme/style/vuepress.css';
import '@kangc/v-md-editor/lib/plugins/highlight-lines/highlight-lines.css';
import axios from "axios";
import {ElMessage} from "element-plus";
import {ref} from "vue";
export default {
  mounted() {
    axios.get('/api/getmd')
        .then(res => {
          this.mdtext = res.data;
          this.runloading=false;
          ElMessage.success('数据加载成功！')
        })
        .catch(err => {
          ElMessage.error('获取md数据错误，错误原因:'+err.data);
          this.runloading=false;
        })
  },
  data() {
    return {
      mdtext: "",
      runloading:ref(true)
    }
  },
  methods:{
    onsave:function (text,html){
      html.valueOf()
      axios.get('/api/savemd?md='+encodeURIComponent(text))
            .then(res =>{
              res.data;
              ElMessage.success('保存成功！')
            })
            .catch(err =>{
              ElMessage.error('保存错误！错误原因:'+err.error)
            })
    }
  }
}
</script>